package data.join.com.database.bean;

import java.io.File;
import java.util.List;

import data.join.com.database.GreenDao;

/**
 * Created by Administrator on 2017/10/16.
 */

public class FileUploadPref {

    public static int UPLOAD_TYPE_VIDEO = 0;
    public static int UPLOAD_TYPE_IMAGE = 1;

    public static int STATUS_UPLOAD_NONE = 0;
    public static int STATUS_UPLOAD_CLOUD = 1;
    public static int STATUS_UPLOAD_ERROR = 2;
    public static int STATUS_UPLOAD_SUCCESS = 1;

    private static String TAG;
    private static FileUploadPref mInstance;

    private FileUploadDao fileUploadDao;

    private FileUploadPref(){
        fileUploadDao = GreenDao.getInstance().sDaoSession.getFileUploadDao();
    }

    public static synchronized FileUploadPref getInstance() {
        if (mInstance == null) {
            mInstance = new FileUploadPref();
        }
        return mInstance;
    }

    public void insertFileUploadById(long mediaId,int type){
        FileUpload videoUpload = new FileUpload();

        videoUpload.mediaId = mediaId;
        videoUpload.type = type;
        videoUpload.status = STATUS_UPLOAD_NONE;

        fileUploadDao.insert(videoUpload);
    }

    public List<FileUpload> queryUnLoadVideo(){
        List<FileUpload> list;

        list = fileUploadDao.queryBuilder()
                .where(FileUploadDao.Properties.Status.eq(STATUS_UPLOAD_NONE),FileUploadDao.Properties.Type.eq(UPLOAD_TYPE_VIDEO))
                .orderDesc(FileUploadDao.Properties.Id)
                .list();

        return list;
    }

    public void updateFileUpload(FileUpload fileUpload){
        fileUploadDao.update(fileUpload);
    }
}
